package com.hx.springboot1.controller;

import com.hx.springboot1.pojo.dto.ChooseDTO;
import com.hx.springboot1.pojo.dto.ScoreModelDTO;
import com.hx.springboot1.pojo.entity.TabYear;
import com.hx.springboot1.pojo.vo.ScoreModelVO;
import com.hx.springboot1.service.impl.ChooseServiceImpl;
import com.hx.springboot1.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Author: hx
 * Date: 2021-05-25 22/02
 * Description: Nothing else
 */
@Controller
public class ChooseController {
    @Autowired
    ChooseServiceImpl chooseService;
    @GetMapping("/selectCourseByStuIdFromChoose")
    @ResponseBody
    public ScoreModelVO selectCourseByStuIdFromChoose(Integer id){
        return chooseService.selectByStuIdFromChoose(id);
    }
    @RequestMapping("/chooseRequest")
    public String chooseRequest(Model model){
        UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = user.getUsername();
        List<ChooseDTO> chooseByStuId = chooseService.getChooseByStuId(username);
        model.addAttribute("info",chooseByStuId);
        System.out.println("----------------------"+chooseByStuId);
        return "reportForms/chooseCourse";
    }
    @GetMapping("/getYear")
    @ResponseBody
    public List<TabYear> getYear(){
        List<TabYear> year = chooseService.getYear();
        return year;
    }
    @PostMapping("/saveChoose")
    @ResponseBody
    public ResultMsg saveChoose(Integer yearId,Integer courseId){
        ResultMsg resultMsg = chooseService.saveChoose(yearId, courseId);
        return resultMsg;
    }
    @GetMapping("/delChoose")
    @ResponseBody
    public ResultMsg delChoose(Integer chooseId){
        return chooseService.delChoose(chooseId);
    }
}
